using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;

namespace Tequila.Phone.Interactivity
{
    /// <summary>
    /// <see cref="EnterKeyDownUpdateSourceTrigger{T}"/> that updates Password property <see cref="Binding">bound</see> data source.
    /// </summary>
    public class PasswordBoxEnterKeyDownUpdateSourceTrigger : EnterKeyDownUpdateSourceTrigger<PasswordBox>
    {
        /// <summary>
        /// Triggers custom actions when Enter <see cref="Key">key</see> down event occured.
        /// </summary>
        protected override void Trigger()
        {
            var binding = AssociatedObject.GetBindingExpression(PasswordBox.PasswordProperty);
            
            if (binding != null)
            {
                binding.UpdateSource();
            }

            base.Trigger();
        }
    }
}